<template>
  <div class="title-wrap " :style="{ 'background-image': `url(${src})` }">
    <div class="title-left">{{ title }}</div>
    <div class="title-right">
      <slot>
        <el-select  v-if="rightType === 'select'"
          placeholder="请选择"
          v-model="selectValue"
          @change="change(selectValue)"
        >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
        </el-select>

        <el-date-picker
          class="picker"
          v-if="rightType === 'month'"
          v-model="monthValue"
          @change="change(monthValue)"
          :editable="false"
          :clearable="false"
          type="month"
          format="yyyy-MM"
          value-format="yyyy-MM"
        ></el-date-picker>
        <i class="el-icon-caret-bottom" style="color:#4bf4c0;" v-show="rightType"></i>
      </slot>
    </div>
  </div>
</template>

<script>

export default {
  name: 'contentTitle',
  data() {
    return {
      selectValue: '',
      monthValue: ''
    };
  },

  props: {
    title: {
      type: String,
      default: ''
    },
    src: {
      type: String,
      default: ''
    },
    rightType: {
      type: String,
      default: ''
    },
    options: {
      type: Array,
      default: () => []
    },
    value: {
      default: ''
    }
  },
  watch: {
    value: {
      handler() {
        switch (this.rightType) {
          case 'select':
            if (this.value !== this.selectValue) {
              this.selectValue = this.value;
            }
            break;
          case 'month':
            if (this.value !== this.monthValue) {
              this.monthValue = this.value;
            }
            break;
        }
      },
      immediate: true
    }
  },
  methods: {
    change(value) {
      this.$emit('input', value);
      if (this.value !== value) {
        this.$emit('change', value);
      }
    }
  }
};
</script>

<style lang="scss" scoped="scoped">
.title-wrap {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border-radius: 4px;
  width: 100%;
  height: 60px;
  color: #ffffff;

  .title-left {
    padding-left: 30px;
    height: 24px;
    font-size: 24px;
    font-weight: 500;
    line-height: 30px;
  }

  .title-right {
    height:28px;
    margin-right: 12px;

    display: flex;
    align-items: center;
    background: linear-gradient(180deg, rgba(30,83,134,0.11) 0%, rgba(30,82,132,0.11) 100%);
    box-shadow: inset 0px 0px 24px 1px #205DA5;
    border-radius: 4px 4px 4px 4px;
    font-size: 16px;
    color:#FFFFFF;
    .el-select {
      ::v-deep .el-input__inner {
        background: none;
        border: none;
        color:#FFFFFF;
        font-size: 16px;
        max-width: 140px;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding-right: 0px;
      }
      ::v-deep .el-input__suffix {
        display: none;
      }
    }

    .picker {
      width: 125px;
      ::v-deep .el-input__inner {
        padding-right: 20px;
        background: none;
        border: none;
        text-align: right;
        max-width: 140px;
        color:#FFFFFF;
        font-size: 16px;
        height: 100%;
        line-height: unset;
        width: 100%;
        cursor: pointer;
      }
      ::v-deep .el-input__suffix-inner {
        display: none;
      }
      ::v-deep .el-input__prefix {
        display: none;
      }
    }
    i{
      padding-right: 12px;
    }
  }
}
</style>
